# 集合可以用来去重， 关键字set
ageList = [1,1,1,2,3,4,5,3,2,1,3,4]
print(len(ageList))
print(ageList.count(1))
ageSet = set(ageList)
print(ageSet)
print(len(ageSet))
ageSet.add(11)
ageSet.add(22)
print(ageSet)
ageSet.remove(22) # 删除指定元素
print(ageSet)
ageSet.pop() # 删除第一个数据
print(ageSet)
ageSet1 = ageSet.copy()
print(ageSet1)
ageSet.clear() # 晴空
print(ageSet)
print(ageSet1)
print(ageSet1.discard(222)) # discard来删除指定元素，没找到不会抛出异常
# 交集
print(ageSet1 & {44,45,46, 4})
print(ageSet1.intersection({44,45,46,4}))
# 并集
print(ageSet1 | {44,45,46, 4})
print(ageSet1.union({44,45,46,4}))
# 差集
print(ageSet1 - {44,45,46, 4})
print(ageSet1.difference({44,45,46,4}))
# 不可变set
ageSet2 = frozenset(ageList)
# ageSet2.add(11) # 报错不能操作
print(ageSet2)

